import Vue from "vue";
import dayjs from "dayjs";
import cool from "sn-cool";

/**
 * @desc 给某个dom添加动画效果
 * @param {*} className  作用于动画的类名dom  String | Array
 * @param {*} offset  距离视窗高度chufa
 * @param {*} callback(dom) 动画开始时候的回调参数是当前动画节点
 * @param {*} scrollContainer 滚动的容器，默认是窗口
 */
Vue.prototype.$cool = function(className, offset = 0, callback, scrollContainer = "window") {
	const options = {
		boxClass: className,
		animateClass: "animated",
		offset: offset,
		callback: callback,
		live: false,
		scrollContainer: scrollContainer,
	};
	if (Array.isArray(className)) {
		className.forEach((name) => {
			options.boxClass = name;
			new cool(options).init();
		});
	} else {
		new cool(options).init();
	}
};

/**
 * @desc 日期格式化
 * @param {*} date 时间日期
 * @param {*} long 默认为true：是否携带十分秒
 * @returns
 */
Vue.prototype.rTimea = function(date, long = true) {
	if (!date) {
		return "";
	}
	const newDate = dayjs(date).format("YYYY-MM-DD HH:mm:ss");
	if (long) {
		return newDate;
	}
	return newDate.split(" ")[0];
};
